package com.example.dialog.Fragment;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.dialog.Adapter.PostAdapter;
import com.example.dialog.R;
import com.example.dialog.Tools.DatabaseHelperForFindItems;
import com.example.dialog.model.Post;

import java.util.ArrayList;
import java.util.List;

public class FollowFragment extends Fragment {
    private RecyclerView rv_find_items;
    private PostAdapter postAdapter;
    private List<Post> posts;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_follow, container, false);

        // 初始化 RecyclerView
        rv_find_items = view.findViewById(R.id.rv_find_items);
        rv_find_items.setLayoutManager(new GridLayoutManager(getContext(), 2));
        //将 RecyclerView 的布局管理器更改为 GridLayoutManager，并设置列数为 2

        // 加载测试数据
        loadTestData();

        return view;
    }

    private void loadTestData() {
        //posts = getTestPosts();  //构造数据
        Context context = getActivity();
        posts = new DatabaseHelperForFindItems(context).queryFollow();//读取数据库
        postAdapter = new PostAdapter();   //连接适配器
        postAdapter.setPosts(posts); // 将获取的数据传递给适配器
        rv_find_items.setAdapter(postAdapter); // 设置适配器
    }
}